package  
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	/**
	 * ...
	 * @author ...
	 */
	public class ClExplosion extends ClObject 
	{
		/* Минимальный размер взрыва */
		public var startWidth:Number;
		public var startHeight:Number;
		public var endWidth:Number;
		public var endHeight:Number;
		
		/* Коэффициенты минимальных и максимальных размеров взрыва */
		public var startSize:Number;
		public var endSize:Number;
		
		public var t:Number;
		public var tSpeed:Number;
		
		// Источник взрыва.
		public var targetObject:ClObject;
		public var targetContent:DisplayObject;
		
		public function ClExplosion(target:ClObject) 
		{
			targetObject = target;
			targetContent = target.DisplayContent;
						
			super(target.stageRef);
			if (Main.useEmbededContent)
				LoadEmbededImage(Assets.ExplosionImage);
			else
				LoadImage("../content/images/explosion1.png");
		}
		
		override protected function InitParams():void 
		{
			super.InitParams();
			
			scaleX = Math.random()*0.5+0.5
			
			rotation = Math.random() * 360;
			
			x = targetObject.x;
			y = targetObject.y;
			
			t = 0;
			tSpeed = 0.1;
			
			startSize = 0.5;
			endSize = 1;
			
			startWidth = startSize * targetObject.width;
			//startHeight = startSize * height;
			endWidth = endSize * targetObject.width;
			//endHeight = endSize * height;
			
			width = startWidth;
			scaleY = scaleX;
			//height = targetObject.height/4;
			
			/* Очищаем указатель на источник взрыва */
			targetObject = null;
			targetContent = null;
		}
		
		override protected function update(e:Event):void 
		{
			super.update(e);
			t += tSpeed;
			if (Math.abs(t) > 1 * Math.PI)
				removeSelf();
			
			width = Math.sin(t) * endWidth + startWidth;
			height = width;
			
			rotation = Math.random() * 360;
			
		}
		
	}

}